/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Defines the states of a user registration.
 *
 * <p>There are two states a user may be in: ACTIVE, and PENDING.</p>
 *
 * <p>Initially, a user is PENDING after they self-regisiter.</p>
 *
 * <p>An admin user then either grants or denies the registration.  Denied users are
 * deleted from the system.  Approved registrations then become ACTIVE.</p>
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "statustype")
@NamedQueries({@NamedQuery(name = "StatusType.findAll", query = "SELECT s FROM StatusType s"),
        @NamedQuery(name = "StatusType.findByStatcd", query = "SELECT s FROM StatusType s WHERE s.statCode = :statCode"),
        @NamedQuery(name = "StatusType.findByDescription", query =
        "SELECT s FROM StatusType s WHERE s.description = :description")})
public class StatusType implements Serializable {
  private static final long serialVersionUID = 1L;

  public static final String ACTIVE_CD = "ACT";
  public static final String PENDING_CD = "PEND";
  public static final String HISTORIC_CD = "HIST";
  
  @Id
  @Basic(optional = false)
  @Column(name = "statcd", nullable = false, length = 8)
  private String statCode;
  @Basic(optional = false)
  @Column(name = "description", nullable = false, length = 30)
  private String description;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "statCode")
  private Collection<RegisteredUser> reguserCollection;

  public StatusType() {
  }

  public StatusType(String statCode) {
    this.statCode = statCode;
  }

  public StatusType(String statCode, String description) {
    this.statCode = statCode;
    this.description = description;
  }

  public String getStatCode() {
    return statCode;
  }

  public void setStatCode(String statCode) {
    this.statCode = statCode;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public Collection<RegisteredUser> getReguserCollection() {
    return reguserCollection;
  }

  public void setReguserCollection(Collection<RegisteredUser> reguserCollection) {
    this.reguserCollection = reguserCollection;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (statCode != null ? statCode.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof StatusType)) {
      return false;
    }
    StatusType other = (StatusType) object;
    if ((this.statCode == null && other.statCode != null) || (this.statCode != null && !this.statCode.equals(other.statCode))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.Statustype[statcd=" + statCode + "]";
  }

}
